import {postRequest} from '@/utils/api'
import {param} from '.'

const $appManageApi = {

  // 页面完成部署配置后进行服务的部署
  deployYaml: param => {
    return postRequest('/gv-kube/appmanage/yaml/deploy', param)
  },

  // 分页获取所有服务实例
  listKubeDeploy: param => {
    return postRequest('/gv-kube/appmanage/yaml/page', param)
  },

  // 从缓存中读取服务实例的状态
  getDeployStatus: param => {
    return postRequest('/gv-kube/appmanage/yaml/status', param)
  },

  // 从缓存中读取服务实例的状态
  getGroupInstanceDeployStatus: param => {
    return postRequest('/gv-kube/appmanage/group/yaml/intance/status', param)
  },

  // 从缓存中读取服务实例的状态
  getDeployDetail: param => {
    return postRequest(`/gv-kube/appmanage/yaml/detail/${param}`, null)
  },
  // 查看yaml文件
  getYamlDetail: param => {
    return postRequest(`/gv-kube/appmanage/yaml/deploymeny/yaml?deployId=${param}`, null)
  },
// 查看Pod日志
  viewPodLogs: param => {
    return postRequest(`/gv-kube/appmanage/yaml/view/logs?podIp=${param.podIp}&namespace=${param.namespace}&podName=${param.podName}`, null)
  },

  // 进入Pod容器
  execPodContainer: param => {
    return postRequest(`/gv-kube/appmanage/yaml/exec/pod?podIp=${param.podIp}&namespace=${param.namespace}`, null)
  },

  // 删除服务实例
  deleteDeploy: param => {
    return postRequest(`/gv-kube/appmanage/yaml/pod/delete?namespace=${param.namespace}&podName=${param.podName}`, null)
  },

  // 查看事件
  getEventInfo: param => {
    return postRequest(`/gv-kube/appmanage/yaml/pod/event?namespace=${param.namespace}&podName=${param.podName}`, null)
  },

  // 页面完成配置部署后进行服务的启动
  startYamlDeploy: param => {
    return postRequest(`/gv-kube/appmanage/yaml/start`, param)
  },

  // 对处于运行状态的服务进行停止
  stopYamlDeploy: param => {
    return postRequest(`/gv-kube/appmanage/yaml/stop`, param)
  },

  // 检查服务实例部署名称是否冲突
  checkDeployName: param => {
    return postRequest(`/gv-kube/appmanage/yaml/checkname/${param}`, null)
  },

  // 检查服务实例部署名称是否冲突
  checkDns: param => {
    return postRequest(`/gv-kube/appmanage/yaml/check/domain?dns=${param}`, null)
  },

  // 根据服务标识获取服务实例
  listByNameAndVersion: param => {
    return postRequest(`/gv-kube/appmanage/yaml/list?appName=${param.appName}&tenantId=${param.tenantId}`, null)
  },

  // 容器服务实例删除
  deleteYamlDeploy: param => {
    return postRequest(`/gv-kube/appmanage/yaml/delete`, param)
  },

  // 获取已部署服务实例的配置
  getDeployConfig: param => {
    return postRequest(`/gv-kube/appmanage/yaml/config/${param}`, null)
  },

  // 获取已部署服务实例的配置
  upgradeYamlDeploy: param => {
    return postRequest(`/gv-kube/appmanage/yaml/upgrade`, param)
  },

  // 获取服务实例所有版本
  rollBackYamlDeploy: param => {
    return postRequest(`/gv-kube/appmanage/version/list/${param}`, null)
  },

  // 容器服务实例回滚
  rollBackYamlDeployByVersion: param => {
    return postRequest(`/gv-kube/appmanage/yaml/rollback?deployId=${param.id}&version=${param.version}`, null)
  },

  // --- 服务组实例相关接口
  // 页面完成部署配置后进行服务组的部署
  createGroupDeploy: param => {
    return postRequest(`/gv-kube/appmanage/group/deploy`, param)
  },

  // 分页获取所有服务组实例
  listGroupDeploy: param => {
    return postRequest(`/gv-kube/appmanage/group/page`, param)
  },

  // 服务组页面实时更新服务组状态
  getGroupDeployStatus: param => {
    return postRequest(`/gv-kube/appmanage/group/yaml/status`, param)
  },

  // 获取服务组下所有服务实例
  listYamlDeploy: param => {
    return postRequest(`/gv-kube/appmanage/group/yaml/list/${param}`)
  },

  // 对部署的服务组实例进行启动
  startGroupDeploy: param => {
    return postRequest(`/gv-kube/appmanage/group/start`, param)
  },

  // 对部署的服务组实例进行停止
  stopGroupDeploy: param => {
    return postRequest(`/gv-kube/appmanage/group/stop`, param)
  },

  // 查看服务关系图
  getrelationGraph: param => {
    return postRequest(`/gv-kube/appmanage/group/get/relationGraph?id=${param}`)
  },

  // 对部署的服务组实例进行删除
  deleteGroupDeploy: param => {
    return postRequest(`/gv-kube/appmanage/group/delete`, param)
  },

  // 资源总览接口
  getTenantDashboard: param => {
    return postRequest(`/gv-kube/tenant/gvKubeTenant/get/dashboard?id=${param}`)
  },

  // 云原生部署接口
  deployCloudYaml: param => {
    return postRequest('/gv-kube/appmanage/cloud/yaml/deploy', param)
  },

  pageCloudYaml: param => {
    return postRequest('/gv-kube/appmanage/cloud/yaml/page', param)
  },

  startCloudYaml: param => {
    return postRequest('/gv-kube/appmanage/cloud/yaml/start', param)
  },

  stopCloudYaml: param => {
    return postRequest('/gv-kube/appmanage/cloud/yaml/stop', param)
  },

  viewCloudYaml: param => {
    return postRequest(`/gv-kube/appmanage/cloud/yaml/view?id=${param}`)
  },

  getCloudYamlById: param => {
    return postRequest(`/gv-kube/appmanage/cloud/yaml/get?id=${param}`)
  },

  deleteCloudYaml: param => {
    return postRequest(`/gv-kube/appmanage/cloud/yaml/delete`, param)
  },

  detailCloudYaml: param => {
    return postRequest(`/gv-kube/appmanage/cloud/yaml/detail?deployId=${param}`)
  },

  versionCloudYamlInstance: param => {
    return postRequest(`/gv-kube/appmanage/cloud/yaml/version?id=${param}`)
  },

  rollbackCloudYaml: param => {
    return postRequest(`/gv-kube/appmanage/cloud/yaml/rollback?id=${param.id}&version=${param.version}`, param)
  },

  rollbackCloudYamlDetail: param => {
    return postRequest(`/gv-kube/appmanage/cloud/yaml/rollback/detail?id=${param.id}&version=${param.version}`, param)
  },

  statusCloudYaml: param => {
    return postRequest('/gv-kube/appmanage/cloud/yaml/status', param)
  },

  upgradeCloudYaml: param => {
    return postRequest('/gv-kube/appmanage/cloud/yaml/upgrade', param)
  },

  // 个人信息相关接口
  getRelTenantByUserId: param => {
    return postRequest(`/gv-kube/userTenantRel/page`, param)
  },

  // 根据用户名修改密码接口
  updatePasswordByName:(param) => {
    return postRequest(`/gv-kube//user/update/password/byname?username=${param.username}&originalPassword=${param.originalPassword}&newPassword=${param.newPassword}`)
  },
  
  getHomePageResources: () => {
    return postRequest("/gv-kube/homepage/get/resources")
  },

  getHomePageTop: () => {
    return postRequest("/gv-kube/homepage/get/top")
  },

  getHomePageLog: () => {
    return postRequest("/gv-kube/homepage/get/log")
  },

  getYamlList: param => {
    return postRequest(`/gv-kube/appmanage/cloud/yaml/list?yamlName=${param}`)
  }
}

export default $appManageApi
